package com.xdf.zipperdye.service;

import com.xdf.zipperdye.dao.business.ContactMapper;
import com.xdf.zipperdye.model.Contact;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
public class ContactServiceImpl implements ContactService {
    @Autowired
    private ContactMapper dao;

    @Override
    public int deleteByPrimaryKey(Integer iid) {
        return dao.deleteByPrimaryKey(iid);
    }

    @Override
    public int insert(Contact record) {
        return dao.insert(record);
    }

    @Override
    public int insertSelective(Contact record) {

        return dao.insertSelective(record);
    }

    @Override
    public Contact selectByPrimaryKey(Integer iid) {
        return dao.selectByPrimaryKey(iid);
    }

    @Override
    public int updateByPrimaryKeySelective(Contact record) {
        return dao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Contact record) {
        return dao.updateByPrimaryKey(record);
    }

    @Override
    public List<Contact> selectBySid(String sid) {
        return dao.selectBySid(sid);
    }

    @Override
    public Boolean sidExists(String sid) {
        List<Contact> contactList = Optional.ofNullable(selectBySid(sid)).orElse(new ArrayList<>());
        return contactList.size() > 0 ? true:false;
    }

    @Override
    public List<Contact> selectAll() {
        return dao.selectAll();
    }
}
